package org.calzz.jajb.utils;

/**
 * Collection of utility methods for reflection-related issues.
 * 
 * @author Marek Brodziak <marek.brodziak@gmail.com>
 * @author Piotr Pejas <piotr.pejas@gmail.com>
 * @since Mar 8, 2008
 */
public class ReflectionUtils {

	/**
	 * Determines whether a class is really a subclass or implementation of
	 * another class.
	 * @param clazz class that is being tested
	 * @param iface class checked for being a supertype
	 * @return true, if tested positive
	 */
	public static boolean isInstanceOf(Class<?> clazz, Class<?> iface) {
		if (clazz.equals(iface)) {
			return true;
		}
		for (Class<?> implementedIFace : clazz.getInterfaces()) {
			if (implementedIFace.equals(iface)) {
				return true;
			}
		}
		if (clazz.getSuperclass() == null) {
			return false;
		}

		return isInstanceOf(clazz.getSuperclass(), iface);
	}

}
